package com.sx.frame.tools;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * cd /storage/emulated/0/Download
 * 移动文件，把不重复的文件移动到E:\迅雷云盘\1
 */
public class AndroidPhoneFileMove {
    public static void main(String[] args) {
//        String path = "D:\\迅雷云盘\\";
        String desPath = "D:\\新建文件夹\\";
        String exitsFile =  "FC2-PPV-4676584.mp4\n" +
                "HEYZO-1590 神田るな 従順すぎる新人マッサージ師 - アダルト動画 HEYZO (ブルーレイ版).mp4\n" +
                "KuwoMusic\n" +
                "MXPlayer_Pro.1.94.0.v8a.Mod.zip\n" +
                "OnePlus\\ Share\n" +
                "OplusDragAndDrop\n" +
                "Peach\\ _4.0(1)\n" +
                "QQ\n" +
                "QQMail\n" +
                "QuarkDownloads\n" +
                "UCDownloads\n" +
                "VideoThumbnail\n" +
                "WeiXin\n" +
                "com_account_usercenter_new\n" +
                "configs.txt\n" +
                "fc2-ppv-1237057-nyap2p.com.mp4\n" +
                "fc2-ppv-1260066-nyap2p.com.mp4\n" +
                "fc2-ppv-4627181-nyap2p.com.mp4";
        String[] split = exitsFile.split("\n");
        List<String> list = Arrays.asList(split);
        List<String> exits = list.stream().map(AndroidPhoneFileMove::processFileName).collect(Collectors.toList());
//        File move = new File("E:\\迅雷云盘");
        File move = new File("D:\\新建文件夹");
        for (File f : move.listFiles()){
            if (exits.contains(processFileName(f.getName()))){
                removeFile(desPath,f.getName());
            }
        }


    }

    public static void removeFile(String path, String name){
        // 定义源文件路径
        Path source = Paths.get(path+name);
        // 定义目标文件路径
        Path destination = Paths.get(path+"1\\"+name);

        try {
            // 移动文件
            Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
            System.out.println("文件"+name+"移动成功！");
        } catch (IOException e) {
            // 处理异常
            System.err.println("移动文件时发生错误: " + e.getMessage());
        }
    }

    //处理文件中的名字
    public static String processFileName(String fileName) {
        fileName = fileName.toUpperCase().replaceAll("-UNCENSORED", "").replaceAll("-HD","").replaceAll("-AI","");
        // 返回处理后的文件名
        String result ;
        String[] split = fileName.split("-");
        if (split.length < 3){
            if (split.length < 2){
                result = split[0];
            }else {
                result =  split[0]+"-"+split[1];
            }
        }else {
            result =  split[0]+"-"+split[1]+"-"+split[2];
        }
        result = result.replace("-","").replace(" ","");
        return result;
    }
}
